<?php

function verifyAccessKey($key)
{
    global $_GCONFIG;
    return $key == $_GCONFIG["access"]["accesskey"];
}

function verifyApplicationKey($key)
{
    global $_GCONFIG;
    return $key == $_GCONFIG["access"]["applicationkey"];
}

function updateSensorData($terminal_id, $device_name, $data)
{
    $dat = base64_encode(json_encode($data));
    TableArray("table_application_sensorData")->insert(array("device_name" => $device_name, "terminal_uuid" => $terminal_id, "upload_data" => $dat), array("terminal_id"));
}

function getCurrentSensorData($terminal_id, $device_name)
{

    $dat = TableArray("table_application_sensorData")->fetch_assoc("`terminal_uuid`=$terminal_id AND `device_name`='$device_name'");

    if ($dat)
        return json_decode(base64_decode($dat["upload_data"]));

    return null;
}
